﻿using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace Sustainalytics.ClientDW.Synchronization.SyncCarbonData
{
    public class CarbonDataSqlDatabase
    {
        private readonly SqlDatabase _database;
        private readonly int _commandTimeout;

        public CarbonDataSqlDatabase(string connectionString, int commandTimeout)
        {
            if (string.IsNullOrEmpty(connectionString))
                throw new Exception("Connection string must be provided!");

            _database = new SqlDatabase(connectionString);
            _commandTimeout = commandTimeout;
        }

        public IDataReader GetCarbonData()
        {
            var command = new SqlCommand
            {
                CommandText = "researchedCompaniesSnapshot_Carbon",
                CommandType = CommandType.StoredProcedure,
                CommandTimeout = _commandTimeout
            };

            return _database.ExecuteReader(command);
        }
    }
}
